package com.ruoyi.easyExcelHandler.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;

public class CustomDateConverter implements Converter<String> {

    /**
     * 开启对 Character 类型的支持
     */
    @Override
    public Class<?> supportJavaTypeKey() {
        return String.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public String convertToJavaData(ReadConverterContext<?> context) {

        String cellStringValue = context.getReadCellData().getStringValue();
        if ("--".equals(cellStringValue)) {
            return null;
        }
        // 这里添加你的转换逻辑，将字符串转换为Date
        // 示例：return DateUtils.parseDate(cellStringValue);
        return context.getReadCellData().getStringValue();

    }

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<String> context) throws Exception {
        return new WriteCellData<>(context.getValue());
    }
    
}
